package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.dto.TbJob;
import com.shenmazong.service.TbJobService;
import com.shenmazong.mapper.TbJobMapper;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 *
 */
@Service
public class TbJobServiceImpl extends ServiceImpl<TbJobMapper, TbJob>
implements TbJobService{
    @Autowired
    private TbJobMapper tbJobMapper;

//    @Override
//    public ResultResponse findAllAdmin(ListParamVo listParamVo) {
//        Page<TbJob> page=tbJobMapper.findAllAdmin(new Page<TbJob>(listParamVo.getCurrent(),listParamVo.getSize()),listParamVo.getParamMap());
//        return ResultResponse.SUCCESS(page);
//    }

    @Override
    public ResultResponse findAllStudent(ListParamVo listParamVo) {
        Page<TbJob> page = new Page<>(listParamVo.getCurrent(), listParamVo.getSize());
        page=tbJobMapper.findAllStudent(page,listParamVo.getParamMap());
        return ResultResponse.SUCCESS(page);
    }

    @Override
    public ResultResponse saveJob(TbJob tbJob) {
        try {
            tbJobMapper.insert(tbJob);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateJob(TbJob tbJob) {
        try {
            TbJob job = tbJobMapper.selectById(tbJob.getJobId());
            if (!StringUtils.isEmpty(tbJob.getJobName())){
                job.setJobName(tbJob.getJobName());
            }
            tbJobMapper.updateById(job);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteJob(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()<=0){
            return ResultResponse.FAILED("至少选择一个哟");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                TbJob job = tbJobMapper.selectById(id);
                job.setDeleteFlag((byte) 1);
                tbJobMapper.updateById(job);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

}




